//
//  HTNetworkTool.swift
//  mySinaBlog
//
//  Created by whtapple on 3/24/16.
//  Copyright © 2016 whtapple. All rights reserved.
//

import UIKit
import AFNetworking
class HTNetworkTool: NSObject {
    //单例模式
    static let sharedInstanse: HTNetworkTool = HTNetworkTool()
    //使init方法私有，防止别人通过这种方式创建
    ///AFN
   let AFNManager: AFHTTPSessionManager = AFHTTPSessionManager(baseURL: HTbaseURL)
    
    private override init() {
        super.init()
        AFNManager.responseSerializer.acceptableContentTypes?.insert("text/plain")
    }
    //封装 GET 方法
    func requestGET(URLString: String, parameters: AnyObject?, callBack: (result: [String : AnyObject]?, error: NSError?) -> ()){
        AFNManager.GET(URLString, parameters: parameters, progress: nil, success: { (_, result) -> Void in
            //转化为字典再传出去
            let dict = result as? [String : AnyObject]
            callBack(result: dict, error: nil)
            }) { (_, error) -> Void in
                callBack(result: nil, error: error)
        }
    }
}
